Clarify useEffect behavior for empty dependency array#1990
Closed
ryancogswell wants to merge 1 commit into
Closed
Conversation
The current wording "If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument." is confusing some people. They are interpreting this as meaning that the effect will run on mount **and** on unmount. See cbdev420's comment on my answer [here](https://stackoverflow.com/questions/56115295/how-to-set-up-an-event-listener-and-remove-it-after-first-fired-event-using-reac/56115564?noredirect=1#comment98864939_56115564).
|
Deploy preview for reactjs ready! Built with commit 446da40 |
Member
|
Sorry we missed this. Closing since we rewrote all of these docs, but if you see this issue still present in the new docs feel free to submit a new PR. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The current wording "If you want to run an effect and clean it up only once (on mount and unmount), you can pass an empty array ([]) as a second argument." is confusing some people. They are interpreting this as meaning that the effect will run on mount and on unmount. See cbdev420's comment on my answer here.